package com.yzfarm.biujoke.biujoke.mvp.presenter;

import android.util.Log;

import com.yzfarm.biujoke.biujoke.mvp.base.BaseView;
import com.yzfarm.biujoke.biujoke.mvp.base.RxPresenter;
import com.yzfarm.biujoke.biujoke.mvp.model.bean.JokeTextBean;
import com.yzfarm.biujoke.biujoke.mvp.model.datamanager.RetrofitManager;
import com.yzfarm.biujoke.biujoke.mvp.view.JokeFragment;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import rx.Scheduler;
import rx.Subscriber;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.schedulers.Schedulers;

/**
 * Created by hanhy on 2016/10/9.
 */

public class JokePresenter extends RxPresenter<JokeFragment> {

    public void getJoke(String page){
         Subscription rxSubscription = RetrofitManager.getInstance().getJokeApi().getJoke(page)
                 .subscribeOn(Schedulers.io())
                 .observeOn(AndroidSchedulers.mainThread())
                 .subscribe(new Subscriber<JokeTextBean>() {
                     @Override
                     public void onCompleted() {
                         Log.d("123","joke completed");

                     }

                     @Override
                     public void onError(Throwable e) {
                         Log.d("123","joke fail");
                     }

                     @Override
                     public void onNext(JokeTextBean jokeTextBean) {
                         Log.d("123","joke success");
                         mView.showJoke(jokeTextBean.getShowapi_res_body().getContentlist());
                     }
                 });
        addSubscrebe(rxSubscription);
        /*Call<JokeTextBean> beanCall = RetrofitManager.getInstance().getJokeApi().getJoke(page);
        beanCall.enqueue(new Callback<JokeTextBean>() {
            @Override
            public void onResponse(Call<JokeTextBean> call, Response<JokeTextBean> response) {
                Log.d("123","joke success");

            }

            @Override
            public void onFailure(Call<JokeTextBean> call, Throwable t) {
                Log.d("123","joke fail");
            }
        });*/

    }

}
